from fastapi import FastAPI
from starlette.responses import FileResponse

from api.wenxinyiyan import api_wenxinyiyan, api_wenxinyige, getconnection, connection

from fastapi.staticfiles import StaticFiles

app = FastAPI()
cursor1 = getconnection().cursor()
sql1 = "TRUNCATE TABLE chat;"
cursor1.execute(sql1)
connection.commit()
app.include_router(api_wenxinyiyan, prefix="/wenxinyiyan", tags=["wenxinyiyan"])
app.include_router(api_wenxinyige, prefix="/wenxinyiyan", tags=["wenxinyige"])

app.mount("/static", StaticFiles(directory="static"), name="static")


@app.get("/")
async def root():
    return FileResponse("static/index.html")


@app.get("/static/{file_path:path}")
async def serve_static_file(file_path: str):
    return FileResponse(f"static/{file_path}")


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="127.0.0.1", port=8000)
